import { _decorator, Component, director, EventTouch, Label, log, Node, tween, v3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('PausePanel')
export class PausePanel extends Component {

    // @property(Node) BgNode: Node = null;
    @property(Node) ConetenNode: Node = null;
    @property(Node) TimeNode: Node = null;

    protected onLoad(): void {
        this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
    }

    protected onEnable(): void {
        //暂停游戏逻辑
        director.pause();

        // 触发是否是最高分
        (window as any).GlobalEventTarget.emit("saveMaxTime");

        //获取分数
        let time;
        (window as any).GlobalEventTarget.emit("getTime", (time1) => {
            time = time1;
        });
        log("time", time);
        let M = Math.floor(time / 60);
        let S = time % 60;
        this.TimeNode.getComponent(Label).string = `当前成绩：${M}分 : ${S}秒`;
    }
    start() {

    }

    update(deltaTime: number) {
    }

    onTouchStart(event: EventTouch) {
        event.propagationStopped = false;
    }

    // 继续游戏
    continueBattle() {
        // 恢复游戏逻辑
        director.resume();
        this.node.active = false;
    }

    // 重新开始
    repeatBattle() {
        // 恢复游戏逻辑
        director.resume();
        director.loadScene("Main");
    }
    // 返回主页
    backHome() {
        // 恢复游戏逻辑
        director.resume();
        director.loadScene("Home");
    }
}


